package com.hiv.controller.wechat;

import cn.hutool.core.util.RandomUtil;
import com.hiv.common.BaseController;
import com.hiv.common.PageInfo;
import com.hiv.common.WebResponse;
import com.hiv.common.param.SendSamplesParam;
import com.hiv.common.param.page.PageQuerySamplingBoxParam;
import com.hiv.mapper.domain.Admin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.hiv.mapper.domain.SamplingBox;
import com.hiv.service.SamplingBoxService;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author zhanghong
 * @version XcxSamplingBoxController.java, v 0.1 2022-09-20 XcxSamplingBoxController Exp $$
 */
@RestController
@RequestMapping("/wechat/samplingBox")
@Api(value = "采样盒子模块", tags = {"【小程序端】采样盒子模块"})
public class XcxSamplingBoxController extends BaseController {
    @Autowired
    private SamplingBoxService samplingBoxService;

    @ApiOperation(value = "分页查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/pageQuery")
    public WebResponse<PageInfo<SamplingBox>> pageQuery(HttpServletRequest request, @RequestBody PageQuerySamplingBoxParam param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingBoxService.pageQuery(param));
    }

    @ApiOperation(value = "列表查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/list")
    public WebResponse<List<SamplingBox>> list(HttpServletRequest request, @RequestBody SamplingBox param) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingBoxService.selectList(param));
    }

    @ApiOperation(value = "根据id查询", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/get/{id}")
    public WebResponse<SamplingBox> getById(HttpServletRequest request, @PathVariable("id") long id) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingBoxService.getById(id));
    }

    @ApiOperation(value = "保存", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/save")
    public WebResponse<Boolean> save(HttpServletRequest request, @RequestBody SamplingBox param) {
        validUserLoginAndGet(request, Admin.class);
        param.setBoxCode(RandomUtil.randomString(8));
        return WebResponse.build(samplingBoxService.save(param));
    }

    @ApiOperation(value = "删除", httpMethod = "POST")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    @PostMapping("/delete")
    public WebResponse<Boolean> delete(HttpServletRequest request, @RequestParam String ids) {
        validUserLoginAndGet(request, Admin.class);
        return WebResponse.build(samplingBoxService.deleteByIds(ids));
    }

    //@ApiOperation(value = "寄样", httpMethod = "POST")
    //@ApiResponses(value = {@ApiResponse(code = 200, message = "success")})
    //@PostMapping("/sendSamples")
    //public WebResponse<Boolean> sendSamples(HttpServletRequest request, @RequestBody SendSamplesParam param) {
    //    validUserLoginAndGet(request, Admin.class);
    //    return WebResponse.build(samplingBoxService.sendSamples(param));
    //}
}
